package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhangyu
 * @data 2023/4/21 14:15
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
@Api("商家端商店状态相关接口")
public class ShopController {
public static final String KET="SHOP_STATUS";
@Autowired
    private RedisTemplate redisTemplate;
    @PutMapping("/{status}")
    @ApiOperation("商家修改店铺状态")
    public Result<String> updateShopStatus(@PathVariable Integer status){
        log.info("修改店铺状态为: {}",status==1?"营业中":"打烊中");
        redisTemplate.opsForValue().set(KET,status);
        return Result.success();
    }
    @GetMapping("/status")
    @ApiOperation("商家端查看店铺状态")
    public Result<Integer> selectShopStatus(){
        return Result.success((Integer)redisTemplate.opsForValue().get(KET));
    }
}
